package com.jswl.training.springjpa.frame;

import io.netty.buffer.ByteBuf;

/**
 * 导航部7B数据帧描述类
 */
public final class Nav7BFrame {
    //region Fields

    /**
     * 信源（设备地址）
     */
    private byte sourcePrimaryId;

    /**
     * 信源（板级地址）
     */
    private byte sourceSecondaryId;

    /**
     * 信宿（设备地址）
     */
    private byte targetPrimaryId;

    /**
     * 信宿（板级地址）
     */
    private byte targetSecondaryId;

    /**
     * 信息类型
     */
    private byte infoType;

    /**
     * 信息长度
     */
    private int infoLength;

    /**
     * 数据类型
     */
    private int dataType;

    /**
     * 数据位长度
     */
    private int bitLength;

    /**
     * 数据内容
     */
    private ByteBuf dataContent;

    //endregion

    //region Constructors

    /**
     *
     */
    public Nav7BFrame() {

    }

    //endregion

    //region Public Methods

    /**
     * @param sourceID
     */
    public void setSource(int sourceID) {
        sourcePrimaryId = (byte) ((sourceID >> 8) & 0xff);
        sourceSecondaryId = (byte) (sourceID & 0xff);
    }

    /**
     * @param targetID
     */
    public void setTarget(int targetID) {
        targetPrimaryId = (byte) ((targetID >> 8) & 0xff);
        targetSecondaryId = (byte) (targetID & 0xff);
    }

    /**
     * @return
     */
    public int getSource() {
        return (sourceSecondaryId & 0xff) | ((sourcePrimaryId & 0xff) << 8);
    }

    /**
     * @return
     */
    public int getTarget() {
        return (targetSecondaryId & 0xff) | ((targetPrimaryId & 0xff) << 8);
    }

    /**
     *
     */
    public void releaseDataContent() {
        if (dataContent != null) {
            dataContent.release();
        }
    }

    //endregion

    //region Getters & Setters

    public int getSourcePrimaryId() {
        return (this.sourcePrimaryId & 0xFF);
    }

    public void setSourcePrimaryId(int sourcePrimaryId) {
        this.sourcePrimaryId = (byte) sourcePrimaryId;
    }

    public int getSourceSecondaryId() {
        return (this.sourceSecondaryId & 0xFF);
    }

    public void setSourceSecondaryId(int sourceSecondaryId) {
        this.sourceSecondaryId = (byte) sourceSecondaryId;
    }

    public int getTargetPrimaryId() {
        return (this.targetPrimaryId & 0xFF);
    }

    public void setTargetPrimaryId(int targetPrimaryId) {
        this.targetPrimaryId = (byte) targetPrimaryId;
    }

    public int getTargetSecondaryId() {
        return (this.targetSecondaryId & 0xFF);
    }

    public void setTargetSecondaryId(int targetSecondaryId) {
        this.targetSecondaryId = (byte) targetSecondaryId;
    }

    public byte getInfoType() {
        return infoType;
    }

    public void setInfoType(byte infoType) {
        this.infoType = infoType;
    }

    public int getInfoLength() {
        return infoLength;
    }

    public void setInfoLength(int infoLength) {
        this.infoLength = infoLength;
    }

    public int getDataType() {
        return dataType;
    }

    public void setDataType(int dataType) {
        this.dataType = dataType;
    }

    public int getBitLength() {
        return bitLength;
    }

    public void setBitLength(int bitLength) {
        this.bitLength = bitLength;
    }

    public ByteBuf getDataContent() {
        return dataContent;
    }

    public void setDataContent(ByteBuf dataContent) {
        this.dataContent = dataContent;
    }

    //endregion

}
